/**
 *
 */
package com.zhuoyue.zhtj.service;

import java.util.List;
import java.util.Map;

import com.eit.eitsite.modules.sys.entity.Dict;
import com.eit.eitsite.modules.sys.utils.DictUtils;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.zhuoyue.zhtj.dao.ClassroominfoDao;
import com.zhuoyue.zhtj.entity.Classroominfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.eit.eitsite.common.persistence.Page;
import com.eit.eitsite.common.service.CrudService;
import com.zhuoyue.zhtj.entity.Dispatchclassroom;
import com.zhuoyue.zhtj.dao.DispatchclassroomDao;

/**
 * 考勤机分布Service
 * @author hss
 * @version 2017-09-26
 */
@Service
@Transactional(readOnly = true)
public class DispatchclassroomService extends CrudService<DispatchclassroomDao, Dispatchclassroom> {
	@Autowired
	private DispatchclassroomDao dispatchclassroomDao;
	@Autowired
	private ClassroominfoDao classroominfoDao;

	public Dispatchclassroom get(String id) {
		return super.get(id);
	}
	
	public List<Dispatchclassroom> findList(Dispatchclassroom dispatchclassroom) {
		return super.findList(dispatchclassroom);
	}
	
	public Page<Dispatchclassroom> findPage(Page<Dispatchclassroom> page, Dispatchclassroom dispatchclassroom) {
		return super.findPage(page, dispatchclassroom);
	}

	public List<Classroominfo> selectClassroomInfo(List<Dispatchclassroom> list){
		List<Classroominfo> lists=Lists.newArrayList();
		for (Dispatchclassroom item:list){
			Classroominfo classroominfo=classroominfoDao.findById(item.getClassroomid());
			if (classroominfo!=null){
				lists.add(classroominfo);
			}
		}
		return lists;
	}
	
	@Transactional(readOnly = false)
	public void save(Dispatchclassroom dispatchclassroom) {
		super.save(dispatchclassroom);
	}
	
	@Transactional(readOnly = false)
	public void delete(Dispatchclassroom dispatchclassroom) {
		super.delete(dispatchclassroom);
	}

	public Map<String,List<Classroominfo>> getDic(){
		Map<String,List<Classroominfo>> map= Maps.newHashMap();
		List<Dict> list= DictUtils.getDictList("sz_xq");
		for(Dict dict:list){
			List<Classroominfo> classroominfos=dispatchclassroomDao.selectClassroomByXq(dict.getValue());
			if(classroominfos!=null&&classroominfos.size()>0){
				map.put(dict.getLabel(),classroominfos);
			}
		}
		return map;
	}
	
}